package com.osi.mes.qm.ui;

import java.io.File;

public class UIHelp {

	// 可以预览图片
	public File[] openPicFiles() {
		MyFileChooser fileChooser = MyFileChooser.getInstance();
		String[][] fileFilter = new String[3][2];
		fileFilter[0][0] = ".jpg";
		fileFilter[0][1] = "jpg";
		fileFilter[1][0] = ".png";
		fileFilter[1][1] = "png";
		fileFilter[2][0] = ".gif";
		fileFilter[2][1] = "gif";
		fileChooser.setInfo(fileFilter, "请选择图片", true);
		fileChooser.setFileSelectionMode(MyFileChooser.OPEN_DIALOG);
		return fileChooser.showOpenFiles();
	}

	// 打开文件
	public File openFiles() {
		String[][] fileFilter = new String[4][2];
		fileFilter[0][0] = ".jpg";
		fileFilter[0][1] = "jpg";
		fileFilter[1][0] = ".png";
		fileFilter[1][1] = "png";
		fileFilter[2][0] = ".gif";
		fileFilter[2][1] = "gif";
		fileFilter[3][0] = ".pdf";
		fileFilter[3][1] = "pdf";
		return openFilesByType(fileFilter, "请选择文件");

	}

	// 打开xls文件
	public File openFilesByType(String[][] fileFilter, String title) {
		MyFileChooser fileChooser = MyFileChooser.getInstance();
		fileChooser.setInfo(fileFilter, title, true);
		fileChooser.setFileSelectionMode(MyFileChooser.OPEN_DIALOG);
		return fileChooser.showOpenFileChooser();
	}

	// 打开指定格式的文件选择框
	public File openFilesByType(String filter, String title) {
		String[][] fileFilter = new String[1][2];
		fileFilter[0][0] = "." + filter;
		fileFilter[0][1] = filter;

		MyFileChooser fileChooser = MyFileChooser.getInstance();
		fileChooser.setInfo(fileFilter, title, true);
		fileChooser.setFileSelectionMode(MyFileChooser.OPEN_DIALOG);
		return fileChooser.showOpenFileChooser();
	}

	// 保存文件
	public String saveFile(String title) {
		String[][] fileFilter = new String[1][2];
		fileFilter[0][0] = ".xls";
		fileFilter[0][1] = ".xls";
		
		MyFileChooser fileChooser = MyFileChooser.getInstance();
		fileChooser.setFileSelectionMode(MyFileChooser.SAVE_DIALOG);
		fileChooser.setInfo(fileFilter, title, true);
		fileChooser.setDialogType(MyFileChooser.SAVE_DIALOG);
		fileChooser.showSaveFileChooser("");
		File selFile = fileChooser.getSelectedFile();
		return selFile.getPath();


	}
	
	public static void main(String[] args)
	{
		UIHelp ui = new UIHelp();
		File f = ui.openFiles();
		System.out.println("file: "+f.getName());
	}

}
